package org.example.frw.response;

import lombok.Data;

@Data
public class AppResponseResult<T> {
  /**
   * 响应状态码，0是正常，非0表示异常
   */
  private int error;
  /**
   * success or ...
   */
  private String type;
  /**
   * 异常信息
   */
  private String msg;
  /**
   * 响应数据
   */
  private T data;

  public static <T> AppResponseResult<T> success() {
    return success(0, null, null);
  }

  public static <T> AppResponseResult<T> success(T data) {
    return success(0, null, data);
  }

  public static <T> AppResponseResult<T> fail(int code, String domain, String message) {
    AppResponseResult<T> r = new AppResponseResult<>();
    r.setError(code);
    r.setMsg(message);
    r.setData(null);
    r.setType(domain);
    return r;
  }

  public static <T> AppResponseResult<T> success(int status, String message, T data) {
    AppResponseResult<T> r = new AppResponseResult<>();
    r.setError(status);
    r.setMsg(message);
    r.setData(data);
    r.setType("success");
    return r;
  }

}

